﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class SysLog
    {
        private readonly Chain.IDAL.SysLog dal = new Chain.IDAL.SysLog();

        public int Add(Chain.Model.SysLog model)
        {
            return this.dal.Add(model);
        }

        public int CleadSysLog(int strDay)
        {
            return this.dal.CleadSysLog(strDay);
        }

        public bool DataBaseInit(ArrayList arrSql)
        {
            return this.dal.DataBaseInit(arrSql);
        }

        public List<Chain.Model.SysLog> DataTableToList(DataTable dt)
        {
            List<Chain.Model.SysLog> list = new List<Chain.Model.SysLog>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.SysLog item = new Chain.Model.SysLog();
                    if ((dt.Rows[i]["LogID"] != null) && (dt.Rows[i]["LogID"].ToString() != ""))
                    {
                        item.LogID = int.Parse(dt.Rows[i]["LogID"].ToString());
                    }
                    if ((dt.Rows[i]["LogUserID"] != null) && (dt.Rows[i]["LogUserID"].ToString() != ""))
                    {
                        item.LogUserID = int.Parse(dt.Rows[i]["LogUserID"].ToString());
                    }
                    if ((dt.Rows[i]["LogActionID"] != null) && (dt.Rows[i]["LogActionID"].ToString() != ""))
                    {
                        item.LogActionID = int.Parse(dt.Rows[i]["LogActionID"].ToString());
                    }
                    if ((dt.Rows[i]["LogType"] != null) && (dt.Rows[i]["LogType"].ToString() != ""))
                    {
                        item.LogType = dt.Rows[i]["LogType"].ToString();
                    }
                    if ((dt.Rows[i]["LogDetail"] != null) && (dt.Rows[i]["LogDetail"].ToString() != ""))
                    {
                        item.LogDetail = dt.Rows[i]["LogDetail"].ToString();
                    }
                    if ((dt.Rows[i]["LogShopID"] != null) && (dt.Rows[i]["LogShopID"].ToString() != ""))
                    {
                        item.LogShopID = int.Parse(dt.Rows[i]["LogShopID"].ToString());
                    }
                    if ((dt.Rows[i]["LogCreateTime"] != null) && (dt.Rows[i]["LogCreateTime"].ToString() != ""))
                    {
                        item.LogCreateTime = DateTime.Parse(dt.Rows[i]["LogCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["LogIPAdress"] != null) && (dt.Rows[i]["LogIPAdress"].ToString() != ""))
                    {
                        item.LogIPAdress = dt.Rows[i]["LogIPAdress"].ToString();
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int LogID)
        {
            return this.dal.Delete(LogID);
        }

        public bool DeleteList(string LogIDlist)
        {
            return this.dal.DeleteList(LogIDlist);
        }

        public bool Exists(int LogID)
        {
            return this.dal.Exists(LogID);
        }

        public DataSet GetActionList(string MemCard)
        {
            return this.dal.GetActionList(MemCard);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.SysLog GetModel(int LogID)
        {
            return this.dal.GetModel(LogID);
        }

        public List<Chain.Model.SysLog> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.SysLog model)
        {
            return this.dal.Update(model);
        }
    }
}

